package com.cloud.core.common.utils.reflect;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * Created by cloudy.xie on 17/12/14.
 */
public abstract class ReflectHelper {

    public static Map<String, ReflectProp> getReflectProp(Object obj) throws IllegalAccessException {
        Map<String, ReflectProp> map = new HashMap<>();
        Class clazz = obj.getClass();

        Field[] fields = clazz.getDeclaredFields();
        if(fields == null || fields.length<=0){
            return map;
        }

        for (Field field :fields){
            if(field.getName()!=null && !Objects.equals(field.getName().trim(),"")){
                field.setAccessible(true);
                ReflectProp prop = new ReflectProp(field.getType().toString(),
                        field.getName(),field.get(obj)==null?null:field.get(obj).toString());
                map.put(prop.getName(),prop);
                field.setAccessible(false);
            }
        }
        return map;
    }

}
